package com.vanzo;

import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.annotation.Nullable;
import android.view.MotionEvent;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.ImageView;

import com.vanzo.talkie.BaseActivity;
import com.vanzo.talkie2.R;

/**
 * Created by tisen on 2018/1/25.
 */

public class AnimationTestActivity extends BaseActivity {

    private ImageView imageView_1, imageView_2;
    private ImageButton send;

    private Animation animation_1, animation_2;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_animation);
        imageView_1 = (ImageView) findViewById(R.id.test_animation_1);
        imageView_2 = (ImageView) findViewById(R.id.test_animation_2);
        send = (ImageButton) findViewById(R.id.test_send);


        animation_1 = AnimationUtils.loadAnimation(this, R.anim.circle_1);
        animation_2 = AnimationUtils.loadAnimation(this, R.anim.circle_2);


        send.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                if (event.getAction() == MotionEvent.ACTION_UP) {

                    imageView_1.setAnimation(null);
                    imageView_2.setAnimation(null);
                    handler.removeMessages(0);
                }
                if (event.getAction() == MotionEvent.ACTION_DOWN) {
                    imageView_1.startAnimation(animation_1);
//                    handler.sendEmptyMessageDelayed(0, 5000);
                    imageView_2.startAnimation(animation_2);
                }
                return false;
            }
        });
    }

    private Handler handler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            imageView_2.startAnimation(animation_1);
        }
    };
}
